﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

using EHTSaleManager.Code.Utility;

namespace EHTSaleManager.UIAdmin
{
    public partial class AdminUsers : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                rpUsers.DataSource = GetUserByRole(HangSo.ROLE_ADMIN);
                rpUsers.DataBind();
            }
        }

        private MembershipUserCollection GetUserByRole(String roleName)
        {
            MembershipUserCollection userList = new MembershipUserCollection();
            MembershipUserCollection allUser = Membership.GetAllUsers(); // lấy tất cả User
            
            if (roleName != "all")
            {
                // chọn các user thuộc nhóm Administrator
                foreach (MembershipUser theUser in allUser)
                {
                    if (Roles.IsUserInRole(theUser.UserName, roleName))
                    {
                        userList.Add(theUser);
                    }
                }
                return userList;
            }

            return allUser;
        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/UIAdmin/AdminUser.aspx");
        }
    }
}